﻿using Dynamics.NAV.Metro.Common;
using Dynamics.NAV.Metro.Data;
using Okra.Core;
using Okra.Navigation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Contacts.Provider;

namespace Dynamics.NAV.Metro.Pages.Vendors
{
    public class VendorsViewModel : BindableBase
    {
        private IList<NavVendor> _Vendors;
        
        public VendorsViewModel()
        {
            this.GoBackCommand = new DelegateCommand(GoBack);
            
            NavVendorDataSource navDataSource = new NavVendorDataSource();
            this.Vendors = navDataSource.GetVendors();
        }

        [ImportingConstructor]
        public VendorsViewModel(INavVendorDataSource navDataSource)
        {
            this.GoBackCommand = new DelegateCommand(GoBack);

            this.Vendors = navDataSource.GetVendors();
        }

        [Import]
        public INavigationManager NavigationManager { get; set; }
 
        public ICommand GoBackCommand { get; private set; }

        public bool CanGoBack
        {
            get { return NavigationManager.CanGoBack; }
        }

        public void GoBack()
        {
            NavigationManager.GoBack();
        }

        public NavVendor SelectedVendor { get;  set; }

        public IList<NavVendor> Vendors
        {
            get
            {
                return _Vendors;
            }
            set
            {
                if (_Vendors != value)
                {
                    _Vendors = value;
                    OnPropertyChanged("Vendors");
                }
            }
        }
    }
}
